from projectadmin.projects.models import Aim, Deliverable, DeliverableType, Objective, Person, Project, Task, WorkPackage
from django.contrib import admin

class TaskInline(admin.TabularInline):
  model = Task
  extra = 1

class TaskAdmin(admin.ModelAdmin):
  fieldsets = [
    (None,               {'fields': ['title', 'lead']}),
    ('Details',          {'fields': ['description', 'estimate']}),
    ('Date Information', {'fields': ['start_date', 'target_date', 'completed_date']}),
  ]
  list_display = ('title', 'start_date', 'target_date', 'completed_date')
  inlines = [TaskInline]

class DeliverableInline(admin.TabularInline):
  model = Deliverable
  extra = 1

class DeliverableAdmin(admin.ModelAdmin):
  list_display=('title', 'completed_date');

class ObjectiveInline(admin.TabularInline):
  model = Objective
  extra=1

class ObjectiveAdmin(admin.ModelAdmin):
  list_display = ['title', 'target_date', 'status']
  inlines = [DeliverableInline]

class AimInline(admin.TabularInline):
  model = Aim
  extra=1

class AimAdmin(admin.ModelAdmin):
  list_display = ('title', )
  list_filter = ['work_package']
  inlines = [ObjectiveInline]

class PersonInline(admin.TabularInline):
  model = Person
  extra = 1

class PersonAdmin(admin.ModelAdmin):
  list_display = ('code', 'first_name', 'last_name')
  inlines = [ObjectiveInline, TaskInline] 

class WorkPackageInline(admin.TabularInline):
  model = WorkPackage
  extra = 1

class WorkPackageAdmin(admin.ModelAdmin):
  list_display = ('code', 'title', 'project')
  list_filter = ['project']
  fieldsets = [
    (None,              {'fields': ['code', 'title']}),
    ('Date Information', {'fields': ['start_date', 'end_date']}),
  ]
  inlines = [AimInline]

class ProjectInline(admin.TabularInline):
  model = Project
  extra = 1

class ProjectAdmin(admin.ModelAdmin):
  list_display = ('code', 'title')
  fieldsets = [
    (None,              {'fields': ['code', 'title', 'description', 'organisation', 'member']}),
    ('Date Information', {'fields': ['start_date', 'end_date']}),
  ]
  inlines = [WorkPackageInline]

admin.site.register(Aim, AimAdmin)
admin.site.register(Deliverable, DeliverableAdmin)
admin.site.register(DeliverableType)
admin.site.register(Objective, ObjectiveAdmin)
admin.site.register(Person, PersonAdmin)
admin.site.register(Project, ProjectAdmin)
admin.site.register(Task, TaskAdmin)
admin.site.register(WorkPackage, WorkPackageAdmin)

